package learnMethod

import (
	"fmt"
	"time"
)

func TestTime() {
	now := time.Now()

	fmt.Printf("值为：%v\n类型为：%T\n", now, now)
	//单独获取年月日时分秒   月需要转成int
	year := now.Year()
	month := now.Month()
	day := now.Day()
	hour := now.Hour()
	minute := now.Minute()
	second := now.Second()
	fmt.Printf("%v年%v月%v日 %v时%v分%v秒\n", year, int(month), day, hour, minute, second)

	//直接格式化
	fmt.Printf(now.Format("2006/01/02 15:04:05\n"))
	fmt.Printf(now.Format("2006/01/02\n"))
	fmt.Printf(now.Format("2006\n"))
	fmt.Printf(now.Format("15:04:05\n"))

	i := 0
	for {
		i++
		fmt.Println(i)
		//休眠100毫秒
		//time.Sleep(time.Millisecond * 100)
		if i == 100 {
			break
		}
	}
	//毫秒时间戳
	unix := now.Unix()
	//纳秒时间戳
	nano := now.UnixNano()
	fmt.Printf("毫秒：%v,纳秒：%v", unix, nano)
}
